import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/style/space.dart';
import 'package:flutter_demo/widget/product_item.dart';
import 'package:flutter_demo/widget/refresher.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import '../../i18n/locale_keys.dart';
import '../../widget/appbar.dart';
import 'goods_product_list_logic.dart';

class Goods_product_listPage extends GetView<Goods_product_listLogic> {
  Goods_product_listPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder(builder: (_){
      return Scaffold(
        appBar: mainAppBarWidget(
          titleString: controller.featured == true ? LocaleKeys.gFlashSellTitle.tr : LocaleKeys.gNewsTitle.tr,
        ),
        body: SmartRefresher(
            controller: controller.refreshController,
            enablePullUp: true,
            onRefresh: controller.onRefresh,
            onLoading: controller.onLoading,
            footer: const SmartRefresherFooterWidget(),
            child:_buildView(),
        ).paddingHorizontal(AppSpace.page),
      );
    },id: "goods_product_list",
      init: Goods_product_listLogic(),
    );
  }

  Widget _buildView() {
    return GridView.builder(
        itemCount: controller.items.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,//每行3个
        mainAxisSpacing: AppSpace.listRow,//主轴间距
        crossAxisSpacing: AppSpace.listItem,//交叉轴间距
        childAspectRatio: 0.7//宽高比
    ),
       itemBuilder: (context,index){
       var product = controller.items[index];
       return ProductItemWidget(
         product,
         imgHeight: 117.w,
       );
    });
  }
}
